package com.yy.young.travel.service.impl;

import com.yy.young.travel.service.IItemService;
import com.yy.young.common.util.CommonUtil;
import com.yy.young.dal.service.IDataAccessService;
import com.yy.young.dal.util.Page;
import com.yy.young.travel.model.Item;
import com.yy.young.travel.util.TravelConstants;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.util.List;

/**
 * 项目服务实现
 * Created by hua on 2018-03-22.
 */
@Service("itemService")
public class ItemServiceImpl implements IItemService {

    @Resource(name = "dataAccessService")
    IDataAccessService dataAccessService;//数据层服务

    private static final Logger logger = LoggerFactory.getLogger(ItemServiceImpl.class);

    //获取数据列表
    @Override
    public List<Item> getItemList(Item item) throws Exception {
        return dataAccessService.getList(TravelConstants.MAPPER.TRAVEL_ITEM + ".getItemList", item);
    }

    //获取数据列表(分页)
    @Override
    public List<Item> getItemPage(Item item, Page page) throws Exception {
        return dataAccessService.getList(TravelConstants.MAPPER.TRAVEL_ITEM + ".getItemList", item, page);
    }

    //查询单条
    @Override
    public Item getItem(String id) throws Exception {
        return (Item)dataAccessService.getObject(TravelConstants.MAPPER.TRAVEL_ITEM + ".getItemById", id);
    }

    //修改
    @Override
    public int updateItem(Item item) throws Exception {
        return dataAccessService.update(TravelConstants.MAPPER.TRAVEL_ITEM + ".update", item);
    }

    //批量删除
    @Override
    public int deleteItem(String[] idArr) throws Exception {
        int i = 0;
        for(String id : idArr){
            i += this.deleteItem(id);
        }
        return i;
    }

    //删除单条
    @Override
    public int deleteItem(String id) throws Exception {
        return dataAccessService.delete(TravelConstants.MAPPER.TRAVEL_ITEM + ".delete", id);
    }

    //插入
    @Override
    public int insertItem(Item item) throws Exception {
        return dataAccessService.insert(TravelConstants.MAPPER.TRAVEL_ITEM + ".insert", item);
    }

    //获得树列表
    public List getItemTreeList(Item item) throws Exception {
        return dataAccessService.getList(TravelConstants.MAPPER.TRAVEL_ITEM + ".getItemTreeList", item);
    }


}